using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Meta.Editor
{
	/// <summary>
	/// Summary description for StyleEditor.
	/// </summary>
	public class StyleEditor : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ListBox styleListBox;
		private System.Windows.Forms.Button OkayButton;
		private System.Windows.Forms.Button editButton;
		private System.Windows.Forms.CheckBox titleCheckBox;
		private System.Windows.Forms.CheckBox commentCheckBox;
		private System.Windows.Forms.Button cancelButton;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Label label2;
		CodeBox code;

		public StyleEditor(CodeBox code)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			this.code = code;
			titleCheckBox.Checked = code.autoStyleTitles;
			commentCheckBox.Checked = code.autoStyleComments;
			styleListBox.SelectedIndex=0;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.styleListBox = new System.Windows.Forms.ListBox();
			this.OkayButton = new System.Windows.Forms.Button();
			this.editButton = new System.Windows.Forms.Button();
			this.titleCheckBox = new System.Windows.Forms.CheckBox();
			this.commentCheckBox = new System.Windows.Forms.CheckBox();
			this.label1 = new System.Windows.Forms.Label();
			this.cancelButton = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// styleListBox
			// 
			this.styleListBox.Font = new System.Drawing.Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.styleListBox.ItemHeight = 18;
			this.styleListBox.Items.AddRange(new object[] {
															  "Normal",
															  "Title",
															  "Comment"});
			this.styleListBox.Location = new System.Drawing.Point(16, 40);
			this.styleListBox.Name = "styleListBox";
			this.styleListBox.Size = new System.Drawing.Size(80, 58);
			this.styleListBox.TabIndex = 0;
			// 
			// OkayButton
			// 
			this.OkayButton.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.OkayButton.Location = new System.Drawing.Point(120, 168);
			this.OkayButton.Name = "OkayButton";
			this.OkayButton.Size = new System.Drawing.Size(80, 24);
			this.OkayButton.TabIndex = 1;
			this.OkayButton.Text = "OK";
			this.OkayButton.Click += new System.EventHandler(this.OkayButton_Click);
			// 
			// editButton
			// 
			this.editButton.Location = new System.Drawing.Point(16, 104);
			this.editButton.Name = "editButton";
			this.editButton.Size = new System.Drawing.Size(80, 24);
			this.editButton.TabIndex = 2;
			this.editButton.Text = "Edit";
			this.editButton.Click += new System.EventHandler(this.editButton_Click);
			// 
			// titleCheckBox
			// 
			this.titleCheckBox.Location = new System.Drawing.Point(168, 40);
			this.titleCheckBox.Name = "titleCheckBox";
			this.titleCheckBox.Size = new System.Drawing.Size(72, 24);
			this.titleCheckBox.TabIndex = 3;
			this.titleCheckBox.Text = "Titles";
			// 
			// commentCheckBox
			// 
			this.commentCheckBox.Location = new System.Drawing.Point(168, 64);
			this.commentCheckBox.Name = "commentCheckBox";
			this.commentCheckBox.Size = new System.Drawing.Size(96, 24);
			this.commentCheckBox.TabIndex = 4;
			this.commentCheckBox.Text = " Comments";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(152, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(144, 23);
			this.label1.TabIndex = 5;
			this.label1.Text = "Set styles automatically for:";
			// 
			// cancelButton
			// 
			this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.cancelButton.Location = new System.Drawing.Point(208, 168);
			this.cancelButton.Name = "cancelButton";
			this.cancelButton.Size = new System.Drawing.Size(80, 24);
			this.cancelButton.TabIndex = 6;
			this.cancelButton.Text = "Cancel";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 16);
			this.label2.Name = "label2";
			this.label2.TabIndex = 7;
			this.label2.Text = "Select style";
			// 
			// StyleEditor
			// 
			this.AcceptButton = this.OkayButton;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.cancelButton;
			this.ClientSize = new System.Drawing.Size(312, 214);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label2,
																		  this.cancelButton,
																		  this.label1,
																		  this.commentCheckBox,
																		  this.titleCheckBox,
																		  this.editButton,
																		  this.OkayButton,
																		  this.styleListBox});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "StyleEditor";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Edit text styles";
			this.ResumeLayout(false);

		}
		#endregion


		private void OkayButton_Click(object sender, System.EventArgs e) {
			code.autoStyleTitles = titleCheckBox.Checked;
			code.autoStyleComments = commentCheckBox.Checked;
		}

		private void editButton_Click(object sender, System.EventArgs e) {
			string styleName = (string)styleListBox.SelectedItem;
			CodeBox.Style style = code.TheStyle(styleName);
			FontDialog f = new FontDialog();
			f.ShowColor = true;
			f.Font = style.font;
			f.Color = style.color;
			DialogResult r = f.ShowDialog();
			if (r==DialogResult.OK)
				code.RegisterStyle(styleName, new CodeBox.Style(f.Font, f.Color));
			f.Dispose();
		}
	}
}
